/*
 * @Description: 定义记分牌类
 * @Author: Zhy
 * @Date: 2024-07-09 10:40:21
 * @LastEditTime: 2024-07-09 10:41:47
 * @LastEditors: Zhy
 */
export default class ScorePanel {
  score = 0; /* 分数 */
  level = 1; /* 等级 */

  maxLevel: number; /* 等级上限 */
  upScore: number; /* 升级所需分数 */

  scoreEl: HTMLElement; /* 分数元素 */
  levelEl: HTMLElement; /* 等级元素 */

  /**
   * @description: 记分牌类的构造函数
   * @Author: Zhy
   * @Date: 2024-07-09 10:36:09
   * @return {*}
   * @param {number} maxLevel 等级上限，默认为10
   * @param {number} upScore 每升一级所需分数，默认为10
   */
  constructor(maxLevel: number = 10, upScore: number = 10) {
    this.scoreEl = document.getElementById("score") as HTMLElement;
    this.levelEl = document.getElementById("level") as HTMLElement;
    this.maxLevel = maxLevel;
    this.upScore = upScore;
  }

  // 设置一个加分的方法
  addScore() {
    this.score++;
    this.scoreEl.innerText = `${this.score}`;

    // 升级条件
    if (this.score % this.upScore === 0) {
      this.levelUp();
    }
  }
  // 设置一个等级提升的方法
  levelUp() {
    if (this.level < this.maxLevel) {
      this.level++;
      this.levelEl.innerText = `${this.level}`;
    }
  }
}
